import  request  from "@/utils/axios";
import { AxiosResponse } from "axios";
import { QueryParams, ResponseData, UserClient } from "./types";


export default {
    // 获取用户列表
    getUsers(params?: QueryParams): Promise<AxiosResponse<ResponseData<UserClient[]>>> {
      return request({
        url: '/api/userClient',
        method: 'get',
        params
      })
    },
  
    // 获取单个用户详情
    getUser(userId: string): Promise<AxiosResponse<ResponseData<UserClient>>> {
      return request({
        url: `/api/userClient/${userId}`,
        method: 'get'
      })
    },
  
    // 创建单个用户
    createUser(data: Partial<UserClient>): Promise<AxiosResponse<ResponseData<UserClient>>> {
      return request({
        url: '/api/userClient',
        method: 'post',
        data
      })
    },
  
    // 批量创建用户
    createUsers(userList: Partial<UserClient>[]): Promise<AxiosResponse<ResponseData<UserClient>>> {
      const formData = new FormData()
      formData.append('UserClientList', JSON.stringify(userList))
      return request({
        url: '/api/userClient',
        method: 'post',
        data: formData
      })
    },
  
    // 更新用户信息
    updateUser(userId: string, data: Partial<UserClient>): Promise<AxiosResponse<ResponseData<UserClient>>> {
      return request({
        url: `/api/userClient/${userId}`,
        method: 'put',
        data
      })
    },
  
    // 敏感信息更新
    sensitiveUpdate(userId: string, data: { is_delete?: number }): Promise<AxiosResponse<ResponseData<UserClient>>> {
      const formData = new FormData()
      Object.entries(data).forEach(([key, value]) => {
        if (value !== undefined) {
          formData.append(key, value.toString())
        }
      })
      return request({
        url: `/api/userClient/update/${userId}`,
        method: 'put',
        data: formData
      })
    },
  
    // 删除用户
    deleteUser(userId: string): Promise<AxiosResponse<ResponseData<any>>> {
      return request({
        url: `/api/userClient/${userId}`,
        method: 'delete'
      })
    },
  }